<template>
  <div>
    <a-card :bordered="false">
      <a-button style="margin-left:20px;margin-top:10px" type="primary" @click="setEvent()">车辆设置</a-button>
      <a-table style="margin:20px" :columns="columnstable" @change="pageShow" :loading="tableLoading" :pagination="pagination" :data-source="data" bordered size="middle">
        <template slot="action" slot-scope="text, record">
          <a @click="modifyEvent(record)">编辑</a>
          <a-divider type="vertical" />
          <a @click="quxiaoEvent(record.id)">删除</a>
        </template>
      </a-table>
      <!-- 车辆设置 -->
      <VehiclesSetting v-bind:type="actionType" v-bind:info="info" v-if="personShow" @cancelEvent="cancelEvent" @successEvent="successEvent"></VehiclesSetting>
    </a-card>
  </div>
</template>
<script>
import VehiclesSetting from '@/views/videoManage/resourceManagement/materialmanagement/configurationsetting/vehiclesSetting'
import { ACCESS_TOKEN, ROLE_NAME } from '@/store/mutation-types'
import Vue from 'vue'
import { dwSettingList, deleteDwsetById } from '@/api/video'
import moment from 'moment'
const data = []
export default {
  components: { VehiclesSetting },
  data() {
    return {
      info: {},
      actionType:1,
      modifyShow: false,
      addShow: false,
      personShow: false,
      columnstable,
      data,
      searchData: [],
      queryParam: {},
      current: 1,
      pageSize: 10,
      selectTime: '',
      tableLoading: false,
      pagination: {
        total: 0,
        showTotal: (total) => `共有 ${total} 条数据`,
      },
      uploadFile: {
        id: 1, //非必填 添加项
        name: '',
        url: '/api/import/manage/dwMeter',
        file: '',
        status: '未上传',
        desc: '',
      },
      headers: {
        authorization: Vue.ls.get('ACCESS_TOKEN'),
      },
    }
  },
  filters: {},
  created() {
    this.queryParam.current = this.current
    this.queryParam.pageSize = this.pageSize
    this.queryParam.type = 1
  },
  mounted() {
    this.getDataInfoFunction()
  },
  methods: {
    //删除
    quxiaoEvent(id) {
      this.$confirm({
        title: '提示',
        content: '确定要删除吗?',
        onOk: () => {
          deleteDwsetById(id).then((response) => {
            if (response != undefined) {
              if (response.code == 200) {
                let type = 'success'
                this.$notification[type]({
                  message: '温馨提示',
                  description: '删除成功!',
                  duration: 3,
                })
                this.getDataInfoFunction()
              }
            }
          })
        },
        onCancel() {},
      })
    },
    //编辑
    modifyEvent(e) {
      this.info = e
      this.actionType = 2
      this.personShow = true
    },
    onChange(date, dateString) {
      this.queryParam.startTime = dateString[0] + ' 00:00:00'
      this.queryParam.endTime = dateString[1] + ' 23:59:59'
      this.selectTime = [moment(dateString[0]), moment(dateString[1])]
    },
    //查询
    selectEvent() {
      this.getDataInfoFunction()
    },
    //获取表格数据
    getDataInfoFunction() {
      this.tableLoading = true
      dwSettingList(this.queryParam)
        .then((response) => {
          const pagination = { ...this.pagination }
          pagination.total = response.data.total
          pagination.pageSize = this.pageSize
          this.pagination = pagination
          this.pagination.current = response.data.current
          this.data = response.data.records
          this.tableLoading = false
        })
        .catch((error) => {
          this.tableLoading = false
        })
    },
    //分页
    pageShow(pagination) {
      this.tableLoading = true
      this.queryParam.current = pagination.current
      this.queryParam.pageSize = pagination.pageSize
      dwSettingList(this.queryParam)
        .then((response) => {
          const pagination = { ...this.pagination }
          pagination.total = response.data.total
          pagination.pageSize = this.pageSize
          this.pagination = pagination
          this.pagination.current = response.data.current
          this.data = response.data.records
          this.tableLoading = false
        })
        .catch((error) => {
          this.tableLoading = false
        })
    },
    successEvent() {
      this.getDataInfoFunction()
      this.addShow = false
      this.personShow = false
      this.modifyShow = false
    },
    addEvent() {
      this.addShow = true
    },
    cancelEvent() {
      this.addShow = false
      this.personShow = false
      this.modifyShow = false
    },
    setEvent() {
      this.actionType = 1
      this.personShow = true
    },
    //自定义上传前
    beforeUpload(record) {
      this.headers.authorization = Vue.ls.get('ACCESS_TOKEN')
    },
    //数据导入
    handleChangeupload(info) {
      let fileList = [...info.fileList]
      // this.$message.success('文件正在上传请稍等!')
      if (info.file.status === 'uploading') {
      }
      if (info.file.status === 'done') {
        if (info.file.response.code == 200) {
          this.$message.success(`${info.file.name}文件,上传成功`)
          this.getDataInfoFunction()
        } else {
          this.$message.success(`${info.file.name}文件,上传失败:${info.file.response.msg}`)
        }
      } else if (info.file.status === 'error') {
        this.$message.error(`${info.file.name}文件,上传失败.`)
      } else if (info.file.status === 'removed') {
      }
    },
  },
}
const columnstable = [
  {
    title: '所属区域',
    dataIndex: 'county',
    width: 100,
    align: 'center',
  },
  {
    title: '关联合同名称',
    dataIndex: 'contractName',
    width: 100,
    align: 'center',
  },
  {
    title: '登高',
    dataIndex: 'highYp',
    width: 100,
    align: 'center',
  },
  {
    title: '普通',
    dataIndex: 'normalYp',
    width: 100,
    align: 'center',
  },
  {
    title: '操作',
    dataIndex: 'action',
    width: 100,
    align: 'center',
    scopedSlots: { customRender: 'action' },
  },
]
</script>
